
<!DOCTYPE html>
<html>

<head>
   
    
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!--360浏览器优先以webkit内核解析-->


<title>添加日常费用报销明细</title>

<link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
<link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="__STATIC__/layout/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
<link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
<link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
<link href="__STATIC__/layout/css/channel.css?v=4.1.0" rel="stylesheet">
<!-- Sweet Alert -->
<link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <style>

    </style>

</head>

<body class="white-bg" style="padding: 3px;font-size: 12px;overflow-x: auto">
    <div class="page-heade">
       <h2 class="title_color text-center">添加日常费用报销明细</h2>
    </div>
    <form action="" class="form-inline" id="form1">
    <input type="hidden" name="aid" id="aid" value="{$aid}"/>
        <table class="table table-bordered bud_hei">
            <thead>
            <tr class="info text-center">
                <td rowspan="2"><button class="btn btn-sm btn-primary" id="addmx" type="button">添加</button></td>
                <td colspan="2">时间</td>
                <td rowspan="2">出发地点</td>
                <td rowspan="2">到达地点</td>
                {volist name="feiyong" id="f"}
                <td rowspan="2">{$f.title}(单位:元)<span class="colorRed">*</span></td>
                {/volist}
                <td rowspan="2">费用说明</td>
                <td rowspan="2">费用计入经销商</td>
            </tr>
            <tr class="info text-center">
                <td>起 <span class="colorRed">*</span></td>
                <td>止 <span class="colorRed">*</span></td>
            </tr>
            </thead>
            <tbody id="tb">
            
            <tr>
                <td><button type="button" class="btn btn-sm btn-danger delthis">删除</button></td>
                <td style="min-width: 130px;width: 130px"><input type="text" name="start[]" class="form-control layer-date start" style="width: 90%" ></td>
                 <td style="min-width: 130px;width: 130px"> <input type="text" name="end[]" class="form-control  layer-date end" style="width: 90%" ></td>
                 <td style="min-width: 250px;width: 250px" >
                      <div class="container-fluid">
                            <div class="row">
                                <div class="col-xs-8">
                                    <div class="input-group"  >
                                        <input type="text" placeholder="请输入关键字或空格查询" class="chufa form-control"  name="chufa[]" value="">
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="selectedOnlyOne " style="display: none;" >
                                      
                                        <span class="inin"></span>
                                        <span class="close">×</span>
                                    </div>
                                </div>
                               <div class="col-xs-4">
                                <button class="btn btn-primary select_chufa" type="button" >选择</button>
                            </div>
                           </div>
                        </div>
                 </td>
                  <td style="min-width: 250px;width: 250px" >
                      <div class="container-fluid">
                            <div class="row">
                                <div class="col-xs-8">
                                    <div class="input-group"  >
                                        <input type="text" placeholder="请输入关键字或空格查询" class="chufa form-control"  name="mudi[]" value="">
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                            </ul>
                                        </div>
                                    </div>
                                    <div class="selectedOnlyOne " style="display: none;" >
                                      
                                        <span class="inin"></span>
                                        <span class="close">×</span>
                                    </div>
                                </div>
                               <div class="col-xs-4">
                                <button class="btn btn-primary select_chufa" type="button" >选择</button>
                            </div>
                           </div>
                        </div>
                 </td>
                 {volist name="feiyong" id="f"}
                 <td style="min-width: 100px;width: 100px"><input type="text" name="fei[{$f.id}][]" style="width:95px;" class="form-control num"></td>
                 {/volist}
                  <td style="min-width: 200px;width: 200px"><input type="text" name="remark[]" class="form-control" style="width: 90%"></td>
                 <td style="min-width: 250px;width: 250px" >
                      <div >
                       
                            <div class="row">
                                <div class="col-xs-8">
                                    <div class="input-group cusName_input"   >
                                        <input type="text" placeholder="请输入关键字或空格查询" class="form-control cusName" name="jxs[]" >
                                        <div class="input-group-btn">
                                            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                                <span class="caret"></span>
                                            </button>
                                            <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                            </ul>
                                        </div>
                                    </div>

                                    <div  class="selectedOnlyOne cusName_queding" style="display: none;">
                                       
                                        <span class="inin"></span>
                                        <span class="close">×</span>
                                    </div>
                                </div>
                                  <div class="col-xs-4">
                                    <button class="btn btn-primary select_jxs" type="button" >选择</button>
                                </div>
                            </div>
                 </td>
            </tr>
           
            </tbody>
        </table>

        <div class="padding-10 text-center"><button class="btn btn-primary save" type="button">保存并返回</button><span class="lr_5"></span><button class="btn btn-warning" type="button" id="fanhui">返回</button></div>
    </form>
  
    
<!-- 全局js -->
<script src="__STATIC__/layout/js/jquery.min.js"></script>
<script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
<!-- Sweet alert -->
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>


<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
$("body").on("blur",".num",function(){
    if(isNaN(parseFloat($(this).val()))){
        $(this).val("0.00");
    }else{
        $(this).val(parseFloat($(this).val()).toFixed(2));
    }
})
$(".save").click(function(){
    $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('detailcaozuo')}",
          data:$('#form1').serialize(),// 你的formid
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
           // alert(data);
            var re=JSON.parse(data);
             if(re["state"]==2){
                swal({
                    title: "错误",
                    text:  re["msg"],
                    type: "warning"
                    });
            }else{
               swal({
                    title: "完成",
                    text:  "操作已成功",
                    type: "success"
                    },function(){
                        parent.location.href="{:url('add')}?aid="+$("#aid").val();
                    });
            }
          }
        });

})
var feis="{$feis}";
$("#addmx").click(function(){
    $.post("{:url('addmx')}",{aid:$("#aid").val(),feis:feis},function(re){
        $("#tb").append(re);
        //经销商搜索自动补全
        $(".cusName").bsSuggest({
            url: '{:url("bs/jxs")}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
             $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
           
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
         //出发搜索自动补全

        $(".chufa").bsSuggest({
            url: "{:url('cityjson')}",
            /*effectiveFields: ["userName", "shortAccount"],
             searchFields: [ "shortAccount"],*/
            effectiveFieldsAlias:{title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onSetSelectValue', function (e, keyword, data) {
            $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
            $(this).val(keyword.key)

        });
         //日期范围限制
        var start = {
            elem: '#tb .start',
            format: 'YYYY-MM-DD',
            //min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                //end.min = datas; //开始日选好后，重置结束日的最小日期
                //end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#tb .end',
            format: 'YYYY-MM-DD',
            //min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                //start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    })
})
//取消单选
    $('body').on('click','.selectedOnlyOne .close',function () {
        $(this).closest('.selectedOnlyOne').hide().find('.inin').html('')
        $(this).closest('.selectedOnlyOne').prev('.input-group').show().find('input').val('')
    })
  //弹出经销商树
  $("body").on("click",".select_jxs",function(){
         var t=$(this);
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("open/jxs2")}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var id =  a.find("#renyuan").val();
                    var name =  a.find("#renyuanname").val();
                    if(id){
                        t.parent().prev().children(".selectedOnlyOne").find('.inin').html(name)
                        t.parent().prev().children(".selectedOnlyOne").show()
                        t.parent().prev().children(".input-group").find('.cusName').val(id)

                        t.parent().prev().children(".input-group").hide()
                    }
                    top.layer.close(i)
                }
            })
            return  false

  })
       
   //经销商搜索自动补全
        $(".cusName").bsSuggest({
            url: '{:url("bs/jxs")}',
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword) {
             $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
                $(this).val(keyword.id)
           
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });
 $("body").on('click','.select_chufa',function (data) {
            var index = layer.getFrameIndex(window.name)
            var t=$(this);
            top.layer.open({
                type:2,
                area:['60%','60%'],
                maxmin:true,
                content:'{:url("sqqy")}',
                btn:['确定','关闭'],
                yes:function (i,o) {
                    var a = $(o).find('iframe').contents()
                    var data =  a.find("#data").val();
                       
                    if(data){

                        data = JSON.parse(data)
                        var str ="";
                        var ids ="";
                        
                            str=data[0].title
                            ids=data[0].id
                        
                       //alert(str);
                        t.parent().prev().children('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(str)
                        t.parent().prev().children('.input-group').children().eq(0).val(str)
                        //t.closest('.chufa').val(str)
                    }
                    top.layer.close(i)
                }
            })
            return  false
            })
        
     //出发搜索自动补全

    $(".chufa").bsSuggest({
        url: "{:url('cityjson')}",
        /*effectiveFields: ["userName", "shortAccount"],
         searchFields: [ "shortAccount"],*/
        effectiveFieldsAlias:{title: "名称"},
        ignorecase: true,
        showHeader: true,
        showBtn: false,     //不显示下拉按钮
        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
        idField: "id",
        keyField: "title",
        clearable: true
    }).on('onSetSelectValue', function (e, keyword, data) {
        $(this).closest('.input-group').hide().next('.selectedOnlyOne').show().find('.inin').html(keyword.key)
        $(this).val(keyword.key)

    });
</script>
<script>
    $(function () {
        $('body').on('click','input[type=text]',function () {
            this.select()
        })
           $('#fanhui').on('click',function () {
                //parent.layer.close(parent.layer.getFrameIndex(window.name))
                    parent.location.href="{:url('add')}?aid="+$("#aid").val();
                    return false
                })
    })
        $(document).on("click",".delthis",function(){
            var t=$(this).parent().parent();
                 swal({
                            title: "提示",
                            text: "您真的要删除么？",
                            type: "warning",
                            showCancelButton: true,
                            confirmButtonColor: "#FF3333",
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            closeOnConfirm: true
                        },function(isConfirm){
                            if(isConfirm){
                                t.remove();
                            }
                        })
                        

        })

    
</script>

<script>
      //日期范围限制
        var start = {
            elem: '#tb .start',
            format: 'YYYY-MM-DD',
            //min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06-16 23:59:59', //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                //end.min = datas; //开始日选好后，重置结束日的最小日期
                //end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#tb .end',
            format: 'YYYY-MM-DD',
            //min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
                //start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
  
  var jieshou = $("#area_id");
 sousuo(jieshou);
       function sousuo(id){
            id.bsSuggest({
            allowNoKeyword: false, //是否允许无关键字时请求数据
            multiWord: true, //以分隔符号分割的多关键字支持
            separator: ",", //多关键字支持时的分隔符，默认为空格
            getDataMethod: "url", //获取数据的方式，总是从 URL 获取
            url: 'http://unionsug.baidu.com/su?p=3&t=' + (new Date()).getTime() + '&wd=',
            /*优先从url ajax 请求 json 帮助数据，注意最后一个参数为关键字请求参数*/
            jsonp: 'cb',
            /*如果从 url 获取数据，并且需要跨域，则该参数必须设置*/
            processData: function (json) { // url 获取数据时，对数据的处理，作为 getData 的回调函数
                var i, len, data = {
                    value: []
                };
                if (!json || !json.s || json.s.length === 0) {
                    return false;
                }

                // console.log(json);
                len = json.s.length;

                jsonStr = "{'value':[";
                for (i = 0; i < len; i++) {
                    data.value.push({
                        word: json.s[i]
                    });
                }
                data.defaults = 'baidu';

                //字符串转化为 js 对象
                return data;
            }
        });

          }
/*$("#addcostbx").click(function(){
    if($("#payWay option").val()==0){
       swal("", "请选择支付方式！", "error")
    }else if($("#threeproject").text()==""){
        swal("", "三级费用科目不能为空！", "error")
    }else if($("#bxcause").val()==""){
        swal("", "报销事由不能为空！", "error")
    }else{
          layer.open({
                type: 2,
                title: '添加日常费用报销明细',
                 area: ['1200px', '600px'],
                fixed: false, //不固定
                maxmin: true,
                content: "{:url('Other/addcostbxDetail')}"
            });
            return false

    }
})*/
</script>
</body>

</html>